import { get, post, put, del } from './request'

// 管理员相关API

/**
 * 获取管理员dashboard数据
 */
export const getDashboardData = () => {
  return get('/admin/dashboard')
}

/**
 * 获取管理员订单列表
 * @param {Object} params - 查询参数
 */
export const getAdminOrders = (params = {}) => {
  return get('/admin/orders', params)
}

/**
 * 获取用户列表
 * @param {Object} params - 查询参数
 */
export const getUsers = (params = {}) => {
  return get('/admin/users', params)
}

/**
 * 更新用户状态
 * @param {number} userId - 用户ID
 * @param {Object} data - 更新数据
 */
export const updateUserStatus = (userId, data) => {
  return put(`/admin/users/${userId}/status`, data)
}

/**
 * 获取用户详情
 * @param {number} userId - 用户ID
 */
export const getUserDetail = (userId) => {
  return get(`/admin/users/${userId}`)
}

/**
 * 更新用户信息
 * @param {number} userId - 用户ID
 * @param {Object} data - 更新数据
 */
export const updateUser = (userId, data) => {
  return put(`/admin/users/${userId}`, data)
}

/**
 * 获取商品列表
 * @param {Object} params - 查询参数
 */
export const getProducts = (params = {}) => {
  return get('/admin/products', params)
}

/**
 * 获取分析数据
 * @param {Object} params - 查询参数
 */
export const getAnalytics = (params = {}) => {
  return get('/analytics/overview', params)
}

/**
 * 获取热门商品
 * @param {Object} params - 查询参数
 */
export const getTopProducts = (params = {}) => {
  return get('/analytics/top-products', params)
}

// 商品管理
export const getAdminProducts = (params = {}) => {
  return get('/admin/products', params)
}

export const updateProduct = (productId, data) => {
  return put(`/admin/products/${productId}`, data)
}

export const deleteProduct = (productId) => {
  return del(`/admin/products/${productId}`)
}

export const createProduct = (data) => {
  return post('/admin/products', data)
}

export const updateProductStock = (productId, data) => {
  return post(`/admin/products/${productId}/stock`, data)
}

// 积分管理
export const getPointsStats = () => {
  return get('/admin/points/stats')
}

export const getPointsRecords = (params = {}) => {
  return get('/admin/points/records', params)
}

export const getPointsUsers = (params = {}) => {
  return get('/admin/points/users', params)
}

export const adjustPoints = (data) => {
  return post('/admin/points/adjust', data)
}

// 权限管理
export const getRoles = () => {
  return get('/permissions/roles')
}

export const getPermissions = () => {
  return get('/permissions/permissions')
}

export const deleteRole = (roleId) => {
  return del(`/permissions/roles/${roleId}`)
}

export const createRole = (data) => {
  return post('/permissions/roles', data)
}

export const updateRole = (roleId, data) => {
  return put(`/permissions/roles/${roleId}`, data)
}

// 订单管理
export const updateOrderStatus = (orderId, data) => {
  return put(`/admin/orders/${orderId}/status`, data)
}

export const refundOrder = (orderId, data) => {
  return post(`/admin/orders/${orderId}/refund`, data)
}

export const exportOrders = (params = {}) => {
  return get('/admin/orders/export/excel', params)
}

// 分析数据
export const getOverviewAnalytics = (params = {}) => {
  return get('/analytics/overview', params)
}

export const getUserAnalytics = (params = {}) => {
  return get('/analytics/user-analysis', params)
}

export const getTrendsAnalytics = (params = {}) => {
  return get('/analytics/trends', params)
}

export const getAdsAnalytics = (params = {}) => {
  return get('/analytics/ads', params)
}

export const getPointsAnalytics = (params = {}) => {
  return get('/analytics/points', params)
}

// 管理员管理
export const getAdminProfile = () => {
  return get('/admin/auth/profile')
}

export const getAdmins = (params = {}) => {
  return get('/admin/admins', params)
}

export const getAdminRoles = () => {
  return get('/admin/roles')
}

export const updateAdminStatus = (adminId, data) => {
  return put(`/admin/admins/${adminId}/status`, data)
}

export const deleteAdmin = (adminId) => {
  return del(`/admin/admins/${adminId}`)
}

export const createAdmin = (data) => {
  return post('/admin/admins', data)
}

export const updateAdmin = (adminId, data) => {
  return put(`/admin/admins/${adminId}`, data)
}

export default {
  getDashboardData,
  getAdminOrders,
  getUsers,
  updateUserStatus,
  getUserDetail,
  updateUser,
  getProducts,
  getAnalytics,
  getTopProducts,
  getAdminProducts,
  updateProduct,
  deleteProduct,
  createProduct,
  updateProductStock,
  getPointsStats,
  getPointsRecords,
  getPointsUsers,
  adjustPoints,
  getRoles,
  getPermissions,
  deleteRole,
  createRole,
  updateRole,
  updateOrderStatus,
  refundOrder,
  exportOrders,
  getOverviewAnalytics,
  getUserAnalytics,
  getTrendsAnalytics,
  getAdsAnalytics,
  getPointsAnalytics,
  getAdminProfile,
  getAdmins,
  getAdminRoles,
  updateAdminStatus,
  deleteAdmin,
  createAdmin,
  updateAdmin
}